package com.cq.hd.merchant.controller;

import com.cq.hd.common.annotation.MerchantLoginUser;
import com.cq.hd.common.entity.MerchantAppLoginUser;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.product.api.TbGoodsApi;
import com.cq.hd.product.api.dto.*;
import com.cq.hd.product.api.vo.GoodsCountVo;
import com.cq.hd.product.api.vo.GoodsPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequestMapping("/businessMerchantGoods")
@Api(tags = "策划人管理关联商户的商品相关接口")
public class BusinessMerchantGoodsController {

    @Autowired
    private TbGoodsApi goodsApi;

    @ApiOperation(value = "获取商户的商品每个状态的个数")
    @ApiResponse(response = GoodsCountVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/getGoodsCount")
    public Result<List<GoodsCountVo>> getGoodsCount(@ApiIgnore @MerchantLoginUser MerchantAppLoginUser merchantAppLoginUser) {
        return goodsApi.getBusinessMerchantGoodsCount(merchantAppLoginUser.getMerchantId());
    }

    @ApiOperation(value = "商品列表")
    @ApiResponse(response = GoodsPageVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/page")
    public Result<Page<GoodsPageVo>> pageGoods(GoodsPageDto goodsPageDto, @ApiIgnore @MerchantLoginUser MerchantAppLoginUser merchantAppLoginUser) {
        goodsPageDto.setBusinessMerchantId(merchantAppLoginUser.getMerchantId());
        return goodsApi.pageGoods(goodsPageDto);
    }

    @ApiOperation(value = "发布商品")
    @ApiImplicitParam(name = "goodsReleaseDto", value = "实体", paramType = "body", dataType = "GoodsReleaseDto")
    @PostMapping("/release")
    public Result<Object> releaseGoods(@RequestBody GoodsReleaseDto goodsReleaseDto, @ApiIgnore @MerchantLoginUser MerchantAppLoginUser merchantAppLoginUser) {
        goodsReleaseDto.setBusinessMerchantId(merchantAppLoginUser.getMerchantId());
        return goodsApi.releaseGoods(goodsReleaseDto);
    }

    @ApiOperation(value = "批量下架商品")
    @ApiImplicitParam(name = "goodsOffDto", value = "实体", paramType = "body", dataType = "GoodsOffDto")
    @PutMapping("/off")
    public Result<Object> offGoods(@RequestBody GoodsOffDto goodsOffDto, @ApiIgnore @MerchantLoginUser MerchantAppLoginUser merchantAppLoginUser) {
        goodsOffDto.setBusinessMerchantId(merchantAppLoginUser.getMerchantId());
        return goodsApi.offGoods(goodsOffDto);
    }

    @ApiOperation(value = "批量上架商品(待发售商品)")
    @ApiImplicitParam(name = "goodsOffDto", value = "实体", paramType = "body", dataType = "GoodsOffDto")
    @PutMapping("/batchOn")
    public Result<Object> batchOnGoods(@RequestBody GoodsOnDto goodsOnDto, @ApiIgnore @MerchantLoginUser MerchantAppLoginUser merchantAppLoginUser) {
        goodsOnDto.setBusinessMerchantId(merchantAppLoginUser.getMerchantId());
        return goodsApi.batchOnGoods(goodsOnDto);
    }

    @ApiOperation(value = "上架商品")
    @ApiImplicitParam(name = "goodsOnDto", value = "实体", paramType = "body", dataType = "GoodsOnDto")
    @PutMapping("/on")
    public Result<Object> onGoods(@RequestBody GoodsOnDto goodsOnDto, @ApiIgnore @MerchantLoginUser MerchantAppLoginUser merchantAppLoginUser) {
        goodsOnDto.setBusinessMerchantId(merchantAppLoginUser.getMerchantId());
        return goodsApi.onGoods(goodsOnDto);
    }

    @ApiOperation(value = "改库存")
    @ApiImplicitParam(name = "goodsStockUpdateDto", value = "实体", paramType = "body", dataType = "GoodsStockUpdateDto")
    @PutMapping("/updateGoodsStock")
    public Result<Object> updateGoodsStock(@RequestBody GoodsStockUpdateDto goodsStockUpdateDto, @ApiIgnore @MerchantLoginUser MerchantAppLoginUser merchantAppLoginUser) {
        goodsStockUpdateDto.setBusinessMerchantId(merchantAppLoginUser.getMerchantId());
        return goodsApi.updateGoodsStock(goodsStockUpdateDto);
    }

    @ApiOperation(value = "改价")
    @ApiImplicitParam(name = "goodsPriceUpdateDto", value = "实体", paramType = "body", dataType = "GoodsPriceUpdateDto")
    @PutMapping("/updateGoodsPrice")
    public Result<Object> updateGoodsPrice(@RequestBody GoodsPriceUpdateDto goodsPriceUpdateDto, @ApiIgnore @MerchantLoginUser MerchantAppLoginUser merchantAppLoginUser) {
        goodsPriceUpdateDto.setBusinessMerchantId(merchantAppLoginUser.getMerchantId());
        return goodsApi.updateGoodsPrice(goodsPriceUpdateDto);
    }

    @ApiOperation(value = "编辑商品")
    @ApiImplicitParam(name = "goodsUpdateDto", value = "实体", paramType = "body", dataType = "GoodsUpdateDto")
    @PutMapping
    public Result<Object> updateGoods(@RequestBody GoodsUpdateDto goodsUpdateDto, @ApiIgnore @MerchantLoginUser MerchantAppLoginUser merchantAppLoginUser) {
        goodsUpdateDto.setBusinessMerchantId(merchantAppLoginUser.getMerchantId());
        return goodsApi.updateGoods(goodsUpdateDto);
    }

    @ApiOperation(value = "删除商品")
    @ApiImplicitParam(name = "id", value = "实体", required = true, paramType = "query", dataType = "Long")
    @DeleteMapping
    public Result<Object> deleteGoods(Long id, @ApiIgnore @MerchantLoginUser MerchantAppLoginUser merchantAppLoginUser) {
        return goodsApi.deleteBusinessMerchantGoods(id, merchantAppLoginUser.getMerchantId());
    }

    @ApiOperation(value = "批量删除商品")
    @ApiImplicitParam(name = "goodsDelDto", value = "实体", paramType = "body", dataType = "GoodsDelDto")
    @DeleteMapping("/batchDeleteGoods")
    public Result<Object> batchDeleteGoods(@RequestBody GoodsDelDto goodsDelDto, @ApiIgnore @MerchantLoginUser MerchantAppLoginUser merchantAppLoginUser) {
        goodsDelDto.setBusinessMerchantId(merchantAppLoginUser.getMerchantId());
        return goodsApi.batchDeleteGoods(goodsDelDto);
    }
}
